#include <cstdio>
#include <cstring>
// TODO:
inline int min(int a, int b) { return a < b ? a : b; }
const int N = 501;
int n, t, r, c;
char map[N][N];
bool vis[N][N];
short dx[4] = {1, 1, -1, -1}, dy[4] = {1, -1, 1, -1};
int dfs(short i, short j) {
	if (i == r + 1 && j == c + 1) return 0;
	short tx = i + dx[0], ty = j + dy[0];
	int mmin = 0x3f3f3f3f;
	if (vis[tx][ty] || tx > r + 1 || ty > c + 1 || tx < 1 || ty < 1) goto two;
	vis[tx][ty] = true;
	if (map[i][j] == '\\')
		mmin = min(mmin, dfs(tx, ty));
	else
		mmin = min(mmin, 1 + dfs(tx, ty));
two:
	tx = i + dx[1], ty = j + dy[1];
	if (vis[tx][ty] || tx > r + 1 || ty > c + 1 || tx < 1 || ty < 1) goto tre;
	vis[tx][ty] = true;
	if (map[i][ty] == '/')
		mmin = min(mmin, dfs(tx, ty));
	else
		mmin = min(mmin, 1 + dfs(tx, ty));
tre:
	tx = i + dx[2], ty = j + dy[2];
	if (vis[tx][ty] || tx > r + 1 || ty > c + 1 || tx < 1 || ty < 1) goto fou;
	vis[tx][ty] = true;
	if (map[tx][j] == '/')
		mmin = min(mmin, dfs(tx, ty));
	else
		mmin = min(mmin, 1 + dfs(tx, ty));
fou:
	tx = i + dx[3], ty = j + dy[3];
	if (vis[tx][ty] || tx > r + 1 || ty > c + 1 || tx < 1 || ty < 1) goto end;
	vis[tx][ty] = true;
	if (map[tx][ty] == '\\')
		mmin = min(mmin, dfs(tx, ty));
	else
		mmin = min(mmin, 1 + dfs(tx, ty));
end:
	return mmin;
}
int main() {
#ifndef ONLINE_JUDGE
#ifdef LOCAL
	freopen("testdata.in", "r", stdin);
	freopen("testdata.out", "w", stdout);
#endif
#ifndef LOCAL
	freopen("cir.in", "r", stdin);
	freopen("cir.out", "w", stdout);
#endif
#endif
	scanf("%d", &t);
	char str[501];
	while (t--) {
		memset(vis, 0, sizeof(vis));
		scanf("%d%d", &r, &c);
		for (int i = 1; i <= r; ++i) {
			scanf("%s", str + 1);
			for (int j = 1; j <= c; ++j) { map[i][j] = str[j]; }
		}
		vis[1][1] = true;
		int ans = dfs(1, 1);
		if (ans != 0x3f3f3f3f)
			printf("%d\n", ans);
		else
			printf("NO SOLUTION\n");
	}
	return 0;
}